﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IAD2
{
    class Network
    {
        protected List<Neuron> _lastPoints;
        protected List<Neuron> _beginPoints;
        protected List<Neuron> _points;
        protected List<Neuron> _pointsWithoutSleep;

        public List<Neuron> points
        {
            get { return _pointsWithoutSleep; }
        }

        public List<Neuron> allPoints
        {
            get { return _points; }
        }


        public Network(List<Neuron> points)
        {
            this._points = new List<Neuron>(points);
            this._beginPoints = new List<Neuron>();
            this._lastPoints = new List<Neuron>();
            foreach (Neuron tempNeuron in this._points)
            {
                _beginPoints.Add(new Neuron(tempNeuron.X, tempNeuron.Y));
                _lastPoints.Add(new Neuron(tempNeuron.X, tempNeuron.Y));
            }
            
        }
        public void sortNeuronsByDistance(Neuron toCompare)
        { 
            _pointsWithoutSleep = new List<Neuron>();
            _lastPoints = new List<Neuron>();
            foreach (Neuron tempNeuron in this._points)
            {
                _lastPoints.Add(new Neuron(tempNeuron.X, tempNeuron.Y));
                if (!tempNeuron.checkSleep())
                {
                    tempNeuron.Distance = tempNeuron.distance(toCompare);
                    _pointsWithoutSleep.Add(tempNeuron);
                }
            }

            this._pointsWithoutSleep.Sort();

        }

        public double diffFirst()
        {
            return diff(_beginPoints);
        }

        public double diffLast()
        {
            return diff(_lastPoints);
        }

        public double diff(List<Neuron> diffList)
        {
            double result = 0;
            int i = 0;
            for (i = 0; i < this._points.Count; i++)
            {
                result += this._points[i].distance(diffList[i]);
            }
            return result / i;
        }

        public double countZombie(double distance = 0.05)
        {
            int result = 0;
            for (int i = 0; i < this._points.Count; i++)
            {
                if (this._points[i].distance(this._beginPoints[i]) < distance)
                    result++;
            }
            return result;
        }

        


    }
}
